﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YJTTool.Core.Global;
using YJTTool.DBBaseServer.Entities;

namespace YJTTool.Core.Utilities
{
    public class TimerTask : InheritBase
    {
        public TimerTask()
        {
            HourList = new ObservableCollection<string>();
            MinuteList = new ObservableCollection<string>();
            SecondList = new ObservableCollection<string>();
            RepeatList = new ObservableCollection<string>();
            for (int i = 0; i <= 23; i++)
            {
                HourList.Add(i.ToString("D2"));
            }
            for (int i = 0; i <= 59; i++)
            {
                MinuteList.Add(i.ToString("D2"));
            }
            for (int i = 0; i <= 59; i++)
            {
                SecondList.Add(i.ToString("D2"));
            }
            for (int i = 0; i <= 5; i++)
            {
                RepeatList.Add(i.ToString("D2"));
            }
            DaysList.Add(new DayItem() { IsSelected = true, Name = "一" });
            DaysList.Add(new DayItem() { IsSelected = true, Name = "二" });
            DaysList.Add(new DayItem() { IsSelected = true, Name = "三" });
            DaysList.Add(new DayItem() { IsSelected = true, Name = "四" });
            DaysList.Add(new DayItem() { IsSelected = true, Name = "五" });
            DaysList.Add(new DayItem() { IsSelected = true, Name = "六" });
            DaysList.Add(new DayItem() { IsSelected = true, Name = "日" });
        }
        private string hour;
        private string minute;
        private string second;
        private string days;
        private string repeat;
        private string timerName;
        private string interval;
        private string message;
        private string hmsReamrk;
        private bool isAvailability;
        public ObservableCollection<string> HourList { get; set; }

        public ObservableCollection<string> MinuteList { get; set; }

        public ObservableCollection<string> SecondList { get; set; }


        public ObservableCollection<string> RepeatList { get; set; }
        private ObservableCollection<DayItem> _daysList = new ObservableCollection<DayItem>();
        public ObservableCollection<DayItem> DaysList
        {
            get => _daysList;
            set
            {
                _daysList = value;
                RaisePropertyChanged();
            }
        }
        private ObservableCollection<DayItem> _selectedDays = new ObservableCollection<DayItem>();
        public ObservableCollection<DayItem> SelectedDays
        {
            get => _selectedDays;
            set
            {
                _selectedDays = value;
                RaisePropertyChanged();
            }
        }
        public string DaysRemak { get; set; }

        public int Id { get; set; }
        /// <summary>
        /// 小时
        /// </summary>
        public string Hour
        {
            get => hour;
            set
            {
                hour = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 分钟
        /// </summary>
        public string Minute
        {
            get => minute;
            set
            {
                minute = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 秒
        /// </summary>
        public string Second
        {
            get => second;
            set
            {
                second = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 重复/天
        /// </summary>
        public string Days
        {
            get => days;
            set
            {
                days = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 重复次数
        /// </summary>
        public string Repeat
        {
            get => repeat;
            set
            {
                repeat = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 定时器名称
        /// </summary>
        public string TimerName
        {
            get => timerName;
            set
            {
                timerName = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 间隔时间
        /// </summary>
        public string Interval
        {
            get => interval;
            set
            {
                interval = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 提示信息
        /// </summary>
        public string Message
        {
            get => message;
            set
            {
                message = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 小时分钟秒
        /// </summary>
        public string HMSReamrk
        {
            get => hmsReamrk;
            set
            {
                hmsReamrk = value;
                RaisePropertyChanged();
            }
        }
        public bool IsAvailability
        {
            get => isAvailability;
            set
            {
                isAvailability = value;
                RaisePropertyChanged();
                var parameters = new GlobalMethodEventParameter(GlobalMethodNames.ScheduledRemindersStatusChanges)
                {
                    SourceModule = "StatusChanges",
                    Value = isAvailability == true ? "1" : "0"
                };
                GlobalMethodEvent.Instance.PushMessage(parameters);
            }
        }
        public TimerTask DbtoDto(timetask value)
        {
            return new TimerTask
            {
                Id = value.Id,
                Hour = value.Hour,
                Minute = value.Minute,
                Second = value.Second,
                Days = value.Days,
                Repeat = value.Repeat,
                TimerName = value.TimerName,
                Interval = value.Interval,
                Message = value.Message,
                HMSReamrk = $"{value.Hour}时{value.Minute}分{value.Second}秒",
                isAvailability = value.Availability == "1" ? true : false
            };
        }
        public timetask DtotoDb(TimerTask value)
        {
            return new timetask
            {
                Id = value.Id,
                Hour = value.Hour,
                Minute = value.Minute,
                Second = value.Second,
                Days = value.Days,
                Repeat = value.Repeat,
                TimerName = value.TimerName,
                Interval = value.Interval,
                Message = value.Message,
                Availability = isAvailability == true ? "1" : "0"
            };
        }
    }
    public class DayItem : InheritBase
    {
        private string _name;
        public string Name
        {
            get => _name;
            set
            {
                _name = value;
                RaisePropertyChanged();
            }
        }

        private bool _isSelected;
        public bool IsSelected
        {
            get => _isSelected;
            set
            {
                _isSelected = value;
                RaisePropertyChanged();
            }
        }
    }
}
